﻿using MediatR;
using SY.BasicData.Api.Read.Applications.Basic.Command;
using SY.BasicData.Domain.Basic;
using SY.BasicData.ErrorCode;
using SY.BasicData.Infrastructures;

namespace SY.BasicData.Api.Read.Applications.Basic.CommandHandler
{
    public class GetStoreCommandHandler : IRequestHandler<GetStoreCommand, ApiResult<List<StoreModel>>>
    {
        private readonly IBaseRepository<StoreModel> storeRepository;

        public GetStoreCommandHandler(IBaseRepository<StoreModel> storeRepository)
        {
            this.storeRepository = storeRepository;
        }

        public Task<ApiResult<List<StoreModel>>> Handle(GetStoreCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<StoreModel>> result = new ApiResult<List<StoreModel>>();
            result.Code = ApiEnum.Success;
            result.Message = "商品信息列表展示成功";
            var list = storeRepository.GetAll();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
